package org.atf.model.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import org.atf.model.entity.DpService;
import org.atf.model.entity.Profile;
import org.atf.model.utils.EntityManagerUtil;

public class DpServiceDAO {
	
	public List<DpService> getDpServices(){	
		EntityManager entityManager=EntityManagerUtil.getEntityManager();
		Query query = entityManager.createQuery("select dp from DpService dp");
		List<DpService> resultList = query.getResultList();
		return resultList;
	}
	public void deleteDpService(int id){
		EntityManager entityManager = EntityManagerUtil.getEntityManager();
	 	DpService dpService=entityManager.find(DpService.class, id);
		entityManager.getTransaction().begin();
		entityManager.remove(dpService);
		entityManager.getTransaction().commit();
		 
	}
	public void updateDpService(DpService dpService){
		EntityManager entityManager = EntityManagerUtil.getEntityManager();
		entityManager.getTransaction().begin();
		entityManager.merge(dpService);
		entityManager.getTransaction().commit();
	
	}
	public void insertDpService(DpService dpService){
		EntityManager entityManager = EntityManagerUtil.getEntityManager();
		entityManager.getTransaction().begin();
		entityManager.persist(dpService);
		entityManager.getTransaction().commit();	
	}
	public List<String> getDpServiceUniqueRegions() {
		EntityManager entityManager = EntityManagerUtil.getEntityManager();
		Query query = entityManager.createQuery("select distinct dp.regionName from DpService dp");
		List<String> resultList = query.getResultList();
		return resultList;
	}
	public List<DpService> getDpGetAllServiceByRegion(String regionName) {
		EntityManager entityManager=EntityManagerUtil.getEntityManager();
		Query query = entityManager.createQuery("select dp from DpService dp where dp.regionName='"+regionName+"'");
		List<DpService> resultList = query.getResultList();
		return resultList;
	}
	public DpService getDpServiceById(Integer id) {
		// TODO Auto-generated method stub
		EntityManager entityManager = EntityManagerUtil.getEntityManager();
	 	DpService dpService=entityManager.find(DpService.class, id);
	 	return dpService;
	}
}
